﻿using BruteForce.NewManagers;
using Microsoft.Xna.Framework;

namespace BruteForce.Animation
{
    public delegate void OnTransitionDoneHandler();

    public abstract class Transition
    {
        public double StartTime;
        public double Value;
        private double _duration;
        public bool Running = false;

        public Transition(double duration)
        {
            Duration = duration;
        }

        public double Duration
        {
            get { return _duration; }
            set { _duration = value*1000; }
        }

        protected double Time
        {
            get { return BFGame.CurrentTime.TotalGameTime.TotalMilliseconds - StartTime; }
        }

        public event OnTransitionDoneHandler OnTransitionDone;

        public virtual void StartTransition()
        {
            Running = true;
            StartTime = BFGame.CurrentTime.TotalGameTime.TotalMilliseconds;
            Value = 0;
            TransitionManager.Instance.AddTransition(this);
        }

        public abstract void Interpolate(GameTime time);

        public void ReportFinish()
        {
            if (OnTransitionDone != null) OnTransitionDone();
            Running = false;
        }
    }

    //b = 0, c = 1 , t = Time, d = Duration.
}